package com.example.smartcity.ui.Adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.smartcity.R;

import java.util.ArrayList;

import okhttp3.Response;

public class SmartBarRecycleViewAdapter extends RecyclerView.Adapter<SmartBarRecycleViewAdapter.MyViewHolder>{

    private int Resource;
    private ArrayList<String> list;
    public SmartBarRecycleViewAdapter(ArrayList<String> list ,int Resource){
        this.list = list;
        this.Resource = Resource;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(Resource,parent,false);
        MyViewHolder myViewHolder = new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        holder.textView.setText(list.get(position));
    }

    @Override
    public int getItemCount() {
        return list.size();
    }




    class MyViewHolder extends RecyclerView.ViewHolder{
        TextView textView;
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.TV_stopMessage);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    recycleViewClickListener.ItemClick(getAdapterPosition());
                }
            });
        }
    }

    public void recycleViewClickListener(setItemClickListener lister) {
        recycleViewClickListener = lister;
    }
    public setItemClickListener recycleViewClickListener;
    public interface setItemClickListener{
        void ItemClick(int position);
    }
}
